package com.woniu.bank.controller;

import com.github.pagehelper.PageInfo;
import com.woniu.bank.dto.FarmerLoanSheetDTO;
import com.woniu.bank.service.FarmerLoanSheetService;
import com.woniu.bank.util.Result;
import com.woniu.bank.vo.FarmerLoanSheetVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ：lgy
 * @description：消失的文件,sql优化
 * @date ：2023/1/4 11:56
 */
@RestController
@RequestMapping("flss")
@Api(tags = "业务查询和申请",description = "所有业务查询和申请接口")
public class FarmerLoanSheetController {
    @Autowired
    private FarmerLoanSheetService farmerLoanSheetService;


    @ApiOperation(value = "模糊查询全部业务",notes ="查询全部业务，可以根据页面选项模糊查询",httpMethod="POST")
    @PostMapping("selFls")
    public Result selFls(@RequestBody FarmerLoanSheetDTO farmerLoanSheetDTO){
        List<FarmerLoanSheetVO> farmerLoanSheetVOS = farmerLoanSheetService.selectFlsVOByFlsDTO(farmerLoanSheetDTO);
        PageInfo<FarmerLoanSheetVO> carpayVOPageInfo = new PageInfo<>(farmerLoanSheetVOS);
        return Result.ok().data("flsVos",carpayVOPageInfo);
    }
    @ApiOperation(value = "详情",notes ="选中一条记录查看详情",httpMethod="POST")
    @PostMapping("selXq/{loanDetailsId}")
    public Result selXq(@PathVariable("loanDetailsId") Long loanDetailsId){
        FarmerLoanSheetVO farmerLoanSheetVO = farmerLoanSheetService.selectXqByPrimaryKey(loanDetailsId);
        return Result.ok().data("flsVo",farmerLoanSheetVO);
    }
    @ApiOperation(value = "根据身份证号查客户",notes ="根据身份证号查询客户信息",httpMethod="POST")
    @PostMapping("selXqByCdn")
    public Result selXqByCdn(String clinetDocumentsNumber){
        FarmerLoanSheetVO farmerLoanSheetVO = farmerLoanSheetService.selectByCdn(clinetDocumentsNumber);
        return farmerLoanSheetVO!=null?Result.ok().data("flsVo",farmerLoanSheetVO):Result.error("没有该客户");
    }
    @ApiOperation(value = "申请贷款",notes ="添加贷款申请，待审查员审查",httpMethod="POST")
    @PostMapping("addDkXq")
    public Result addDkXq(@RequestBody FarmerLoanSheetVO farmerLoanSheetVO){
        int i = farmerLoanSheetService.insertDk(farmerLoanSheetVO);
        return i==2?Result.ok():Result.error("系统错误");
    }

}
